home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
157_01
/
qed6
< prev
next >
Wrap
Text File
|
1987-10-10
|
10KB
|
486 lines
/* VERSION 0014 (DATE: 27/02/87) (TIME: 12:57) */
/*
e (qed) screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
August-December 1981
Modified: Aug-Dec 1984: BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
March 1985: BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
FUNCTIONS: blockpos,blockops,putpart,listfile,reform
PURPOSE: performs block commands
*/
#include "qed.h"
char *firstwhite();
blockpos(oldpos)
int oldpos;
{
char c;
int to;
if (oldpos) putstr("| or |P|rev.");
do {
resetcursor();
switch ((c=getkey())) {
case DOWNKEY :
moveline(1);
break;
case UPKEY :
moveline(-1);
break;
case LEFTKEY :
movechar(-1);
break;
case RIGHTKEY :
movechar(1);
break;
case LEFTWKEY :
moveword(-1);
break;
case RIGHTWKEY :
moveword(1);
break;
case BOLKEY :
sync(0);
break;
case EOLKEY :
sync(strlen(text));
break;
case UPPAGE :
movepage(-1);
break;
case DOWNPAGE :
movepage(0);
break;
case HOMEKEY :
if (jumpline(lastl-cline)) sync(strlen(text));
break;
case BOFKEY :
if (jumpline(1-cline)) sync(0);
break;
case JUMPKEY :
if (expert) xprtmess("Jump to: ");
else putmess("Jump to? ");
scans(ans,6);
if ((to=atoi(ans)))
jumpline(to-cline);
break;
case QWIKKEY :
info();
break;
case REPKEY :
repeat=YES;
dofindrep(1);
repeat=NO;
break;
case 'p' :
case 'P' :
if (oldpos) return PREV;
break;
case ESCKEY :
return FAIL;
default :
;
}
}
while (c != CR);
return cline;
}
blockops()
{
int oldcline, oldcharn, oldto, oldfrom, op;
int l, ll, line, *t, shifts, shiftx, cp;
char *txt, c, shift[LLIM];
puttext();
oldcline=cline;
oldcharn=charn;
oldfrom=from;
oldto=to;
if (expert) xprtmess("Q/X/R/B/J-rep ? ");
else
putmess("Q|uit, |X|it w/ save, |R|ead file, |B|lock moves, |J|ump repeat ? ");
while ((op = getlow()) != 'q' && op != 'x' && op != 'r' && op != 'b' &&
op != 'j' && op != ESCKEY);
if (op == ESCKEY) goto clrblk;
putch(op);
switch (op) {
case 'q':
return('q');
break;
case 'x':
return('x');
break;
case 'r':
return ('r');
break;
case 'j':
if (jmpto > 1) jumpline(jmpto-cline);
else calcjmp();
if (expert) xmessoff();
return (NO);
break;
default:
optmess:
#if WWRAP
if (expert) xprtmess("W/P/S/R/M/C/D ? ");
else
putmess("W|rite to file, |P|rint, |S|hift, |R|eformat, |M|ove, |C|opy, or |D|elete block ? ");
while ((op=getlow()) != 'w' && op != 'p' && op != 's' && op != 'r'
&& op != 'm' && op != 'c' && op != 'd' && op != ESCKEY);
#else
if (expert) xprtmess("W/P/S/M/C/D ? ");
else
putmess("W|rite to file, |P|rint, |S|hift, |M|ove, |C|opy, or |D|elete block ? ");
while ((op=getlow()) != 'w' && op != 'p' && op != 's'
&& op != 'm' && op != 'c' && op != 'd' && op != ESCKEY);
#endif
if (op == ESCKEY) goto clrblk;
switch (op) {
case 'w':
if (expert) putstr("W");
else putstr("Write");
break;
case 'p':
if (expert) putstr("P");
else putstr("Print");
break;
case 's':
if (expert) putstr("S");
else putstr("Shift");
break;
#if WWRAP
case 'r':
if (expert) putstr("R");
else putstr("Reformat");
break;
#endif
case 'm':
if (expert) putstr("M");
else putstr("Move");
break;
case 'c':
if (expert) putstr("C");
else putstr("Copy");
break;
case 'd':
if (expert) putstr("D");
else putstr("Delete");
break;
}
from=cline;
to=0;
blocking=YES;
if (expert) xprtmess("Cursor on end line + <CR>");
else
putmess("|Put cursor on line |end|ing block and press [return]");
if ( (to=blockpos(oldto)) == FAIL) {
to=cline;
goto abort;
}
if (to == PREV) {
moveline(oldfrom-cline);
from=cline;
moveline(oldto-cline);
to=cline;
}
if (to < from) {
l=to;
to=from;
from=l;
}
switch (op) {
case 'w':
if (expert) xprtmess("File? ");
else putmess("File to write to? ");
if (scans(name,15) != ESCKEY)
if (exists(name)) writefile(from,to,name,name,NO);
break;
case 'p':
listfile(from,to);
break;
case 's':
if (expert) xprtmess("Changes: ");
else
putmess("Delete/insert spaces/tabs| to shift line, and press [return]");
moveline(from-cline);
sync(0);
resetcursor();
shifts=0;
while ( (c=getkey()) != CR) {
switch (c) {
case DELRIGHT:
if ((text[0] == ' ') || (text[0] == '\t') ||
( (text[0]>0x20) && (text[0]<0x80)) )
deletechar(0);
break;
case ' ':
insertchar(' ');
break;
case TAB:
insertchar('\t');
break;
case ESCKEY:
goto abort;
default: /*28.i.87: add chars to lines*/
if( (c>0x20) && (c<0x80)) insertchar(c);
}
shift[shifts++]=c;
sync(0);
resetcursor();
}
altered=YES;
puttext();
for (l=from+1; l <= to; l++) {
gettext(l);
for (shiftx=0; shiftx < shifts; shiftx++) {
switch((c=shift[shiftx])) {
case DELRIGHT:
/*if (*(txt=&text[0]) == ' ' || *txt == '\t') [28.i.87]*/
if(*(txt=&text[0]))
while ( (*txt=*(txt+1))) txt++;
break;
/* ORIGINAL
case ' ':
case TAB:
if ((cp=strlen(text)) < (LLIM-1)) {
for (; cp >= 0; cp--)
text[cp+1]=text[cp];
text[0]= (c == ' ' ? ' ':'\t');
}
break;
*/ /*28.I.87*/
default:
if ((cp=strlen(text)) < (LLIM-1)) {
for (; cp >= 0; cp--)
text[cp+1]=text[cp];
/*text[0]= (c == ' ' ? ' ':'\t');*/
if(c==TAB) text[0]='\t';
else text[0]=c;
}
}
}
altered=YES;
puttext();
}
changed=YES;
break;
#if WWRAP
case 'r':
reform(from,to);
changed=YES;
break;
#endif
case 'd':
deltp(from,to-from+1);
gettext(loc(from,-1));
charn=adjustc(oldcharn);
from=to=0;
changed=YES;
break;
case 'm':
case 'c':
if (expert) xprtmess("Cursor on line above block + <CR>");
else
putmess("|Put cursor on |line under which block is to go |and press [return]");
if ( (cline=line=blockpos(0)) == FAIL) {
cline=oldcline;
break;
}
for (l=from; l <= to; l++) {
if ((line=inject(line,getline(l))) == FAIL) break;
if (op == 'm') {
deltp( (l<line?l:l+1),1);
if (to < line) {
to--;
l--;
line--;
cline--;
}
}
else {
if (to >= line) to++;
if (l >= line) l++;
if (l == cline) l=line;
}
}
from=cline+1;
to=line;
changed=YES;
break;
}
abort:
blocking=NO;
switch (op) {
case 'w':
case 'p':
case 's':
gettext(oldcline);
charn=oldcharn;
putpart(from,to);
break;
case 'd':
putpart(cline,cline+SHEIGHT);
break;
#if WWRAP
case 'r':
#endif
case 'm':
case 'c':
putpage();
break;
}
clrblk:
if (expert) xmessoff();
return NO;
} /* outer case */
} /* func blockops */
putpart(start,fin)
int start,fin;
{
int l, y;
if (start < pfirst) putpage();
else
for (l=start, y=topline+(start-pfirst); l <= fin && y <= SHEIGHT;
l++, y++) {
if (l == cline) cursory=y;
putline(l,y);
}
}
listfile(from,to)
int from,to;
{ /*10*/
int l,cp,i;
char *t;
puttext();
for (l=from; l<=to; l++) { /*20*/
if (l%10 == 0) putlineno(l);
for (cp=0, t=getline(l); *t; t++)
if (*t == '\t') for (i=tabwidth-cp%tabwidth; i>0 ; cp++, i--)
_os(LSTOUT,' ');
else { /*30*/
/*if (*t > CTRL) _os(LSTOUT,*t);*/
#if PRINTALL
_os(LSTOUT,*t);
#else
if (*t > 0x19) _os(LSTOUT,*t); /* send some ctrl char*/
else { /*40*/ /* for OKI & CITOH */
switch (*t) { /*50*/
case (0x08):
case (0x0a):
case (0x0c):
case (0x0d):
case (0x18):
_os(LSTOUT,*t);
break;
default: { /*60*/
_os(LSTOUT,'^');
_os(LSTOUT,*t+64);
} /*60*/
} /*50*/
} /*40*/
#endif
cp++;
} /*30*/
_os(LSTOUT,'\r');
_os(LSTOUT,'\n');
if (testkey() == ESCKEY) { /*70*/
error("Listing aborted